#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 200 + 1;
int graph[maxn][maxn];
int book[maxn][maxn];//book[i][j]=1 代表地图上graph[i][j]已经访问过
int n, m;//地图大小 n行m列


int fx[4][2] = {{0,  1},
                {1,  0},
                {0,  -1},
                {-1, 0}};
int tot = 0;//当前区域的面积
int max_area = 0;//最大区域面积
int islands = 0;//区域个数

int data[maxn * maxn][2], head = 0, tail = -1;//队列数据结构
int bfs(int sx, int sy) {
    int tot = 0;
    ++tail;
    data[tail][0] = sx;
    data[tail][1] = sy;
    book[sx][sy] = 1;//入队标记
    while (head <= tail) {
        int hx = data[head][0], hy = data[head][1];//访问头结点
        //cout << graph[hx][hy] << " ";
        ++head;//头结点出队
        ++tot;
        for (int i = 0; i < 4; i++) {
            int nx = hx + fx[i][0];
            int ny = hy + fx[i][1];
            if (nx < 0 || nx >= n || ny < 0 || ny >= n || book[nx][ny] == 1 || graph[nx][ny] == 0)continue;
            ++tail;
            data[tail][0] = nx;
            data[tail][1] = ny;
            book[nx][ny] = 1;//入队标记
        }
    }
    return tot;

}

int main() {
    freopen("J.in", "r", stdin);
    int T;
    cin >> T;
    while (T--) {
        cin >> n >> m;
        memset(book, 0, sizeof(book));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                cin >> graph[i][j];
            }
        }
        max_area = 0;
        islands = 0;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++) {
                if (graph[i][j] == 1 && book[i][j] == 0) {
                    ++islands;
                    tot = bfs(i, j);
                    if (tot > max_area) {
                        max_area = tot;
                    }
                }
            }
        cout<< max_area << endl;//最大岛屿max_area
        cout <<islands << endl;//islands

    }
    return 0;
}